package org.mat.ipaas.ucenter.bff.admin.modules.system;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.api.system.ThirdAppRestAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 第三方App对接
 *
 */
@Slf4j
@RestController("thirdAppController")
@RequestMapping("/sys/thirdApp")
public class ThirdAppController {

    @Autowired
    ThirdAppRestAPI thirdAppRestAPI;

    /**
     * 获取启用的系统
     */
    @GetMapping("/getEnabledType")
    public MatApiResponse getEnabledType() {
        MatApiResponse matApiResponse = thirdAppRestAPI.getEnabledType();
        return matApiResponse;
    }

    /**
     * 同步本地[用户]到【企业微信】
     *
     * @param ids
     * @return
     */
    @GetMapping("/sync/wechatEnterprise/user/toApp")
    public MatApiResponse syncWechatEnterpriseUserToApp(@RequestParam(value = "ids", required = false) String ids) {
        MatApiResponse matApiResponse = thirdAppRestAPI.syncWechatEnterpriseUserToApp(ids);
        return matApiResponse;
    }

    /**
     * 同步【企业微信】[用户]到本地
     *
     * @param ids 作废
     * @return
     */
    @GetMapping("/sync/wechatEnterprise/user/toLocal")
    public MatApiResponse syncWechatEnterpriseUserToLocal(@RequestParam(value = "ids", required = false) String ids) {
        MatApiResponse matApiResponse = thirdAppRestAPI.syncWechatEnterpriseUserToLocal(ids);
        return matApiResponse;
    }

    /**
     * 同步本地[部门]到【企业微信】
     *
     * @param ids
     * @return
     */
    @GetMapping("/sync/wechatEnterprise/depart/toApp")
    public MatApiResponse syncWechatEnterpriseDepartToApp(@RequestParam(value = "ids", required = false) String ids) {
        MatApiResponse matApiResponse = thirdAppRestAPI.syncWechatEnterpriseDepartToApp(ids);
        return matApiResponse;
    }

    /**
     * 同步【企业微信】[部门]到本地
     *
     * @param ids
     * @return
     */
    @GetMapping("/sync/wechatEnterprise/depart/toLocal")
    public MatApiResponse syncWechatEnterpriseDepartToLocal(@RequestParam(value = "ids", required = false) String ids) {
        MatApiResponse matApiResponse = thirdAppRestAPI.syncWechatEnterpriseDepartToLocal(ids);
        return matApiResponse;
    }

    /**
     * 同步本地[部门]到【钉钉】
     *
     * @param ids
     * @return
     */
    @GetMapping("/sync/dingtalk/depart/toApp")
    public MatApiResponse syncDingtalkDepartToApp(@RequestParam(value = "ids", required = false) String ids) {
        MatApiResponse matApiResponse = thirdAppRestAPI.syncDingtalkDepartToApp(ids);
        return matApiResponse;
    }

    /**
     * 同步【钉钉】[部门]到本地
     *
     * @param ids
     * @return
     */
    @GetMapping("/sync/dingtalk/depart/toLocal")
    public MatApiResponse syncDingtalkDepartToLocal(@RequestParam(value = "ids", required = false) String ids) {
        MatApiResponse matApiResponse = thirdAppRestAPI.syncDingtalkDepartToLocal(ids);
        return matApiResponse;
    }

    /**
     * 同步本地[用户]到【钉钉】
     *
     * @param ids
     * @return
     */
    @GetMapping("/sync/dingtalk/user/toApp")
    public MatApiResponse syncDingtalkUserToApp(@RequestParam(value = "ids", required = false) String ids) {
        MatApiResponse matApiResponse = thirdAppRestAPI.syncDingtalkUserToApp(ids);
        return matApiResponse;
    }

    /**
     * 同步【钉钉】[用户]到本地
     *
     * @param ids 作废
     * @return
     */
    @GetMapping("/sync/dingtalk/user/toLocal")
    public MatApiResponse syncDingtalkUserToLocal(@RequestParam(value = "ids", required = false) String ids) {
        MatApiResponse matApiResponse = thirdAppRestAPI.syncDingtalkUserToLocal(ids);
        return matApiResponse;
    }

    /**
     * 发送消息测试
     *
     * @return
     */
    @PostMapping("/sendMessageTest")
    public MatApiResponse sendMessageTest(@RequestBody JSONObject params, HttpServletRequest request) {
        String accessToken = request.getHeader("X-Access-Token");
        MatApiResponse matApiResponse = thirdAppRestAPI.sendMessageTest(accessToken,params);
        return matApiResponse;
    }

    /**
     * 撤回消息测试
     *
     * @return
     */
    @PostMapping("/recallMessageTest")
    public MatApiResponse recallMessageTest(@RequestBody JSONObject params) {
        MatApiResponse matApiResponse = thirdAppRestAPI.recallMessageTest(params);
        return matApiResponse;
    }

}
